﻿Imports System.Collections.Generic
Imports System.Linq
Imports System.Text


''' <summary>
''' Clase que define la entidad de negocio Usuario
''' </summary>
''' <remarks></remarks>
Public Class cUsuario

    Private _iUsu_Legajo As Int16
    Private _sUsu_Nombre As String
    Private _sUsu_Apellido As String
    Private _oIdioma As cIdioma
    Private _oEstado_Usuario As cEstado_Usuario
    Private _iDVH As Int32

    Private _ListPassword As List(Of cPassword)
    Private _ListPatenteFamilia As List(Of cPatenteFamiliaElement)

    Private _PasswordActual As cPassword


    Public Property Usu_Legajo() As Int16
        Get
            Return _iUsu_Legajo
        End Get
        Set(value As Int16)
            _iUsu_Legajo = value
        End Set
    End Property

    Public Property Usu_Nombre() As String
        Get
            Return _sUsu_Nombre
        End Get
        Set(value As String)
            _sUsu_Nombre = value
        End Set
    End Property

    Public Property Usu_Apellido() As String
        Get
            Return _sUsu_Apellido
        End Get
        Set(value As String)
            _sUsu_Apellido = value
        End Set
    End Property

    Public Property Idioma() As cIdioma
        Get
            Return _oIdioma
        End Get
        Set(value As cIdioma)
            _oIdioma = value
        End Set
    End Property

    Public Property Estado_Usuario() As cEstado_Usuario
        Get
            Return _oEstado_Usuario
        End Get
        Set(value As cEstado_Usuario)
            _oEstado_Usuario = value
        End Set
    End Property
    'TODO: Colección cFam_Usuario
    'TODO: Colección cPatente_Usuario

    Public Property DVH() As Int32
        Get
            Return _iDVH
        End Get
        Set(value As Int32)
            _iDVH = value
        End Set
    End Property

    Public Property ListPassword() As List(Of cPassword)
        Get
            Return _ListPassword
        End Get
        Set(value As List(Of cPassword))
            _ListPassword = value
        End Set
    End Property

    Public Property ListPatenteFamilia() As List(Of cPatenteFamiliaElement)
        Get
            Return _ListPatenteFamilia
        End Get
        Set(value As List(Of cPatenteFamiliaElement))
            _ListPatenteFamilia = value
        End Set
    End Property

    Public Property PasswordActual()
        Get
            Return _PasswordActual
        End Get
        Set(value)
            _PasswordActual = value
        End Set
    End Property

    Public Sub New()
        _oIdioma = New cIdioma
        _oEstado_Usuario = New cEstado_Usuario

        _ListPassword = New List(Of cPassword)
        _ListPatenteFamilia = New List(Of cPatenteFamiliaElement)

        _PasswordActual = New cPassword
    End Sub

    Public Sub New(iUsu_Legajo As Int16)
        _iUsu_Legajo = iUsu_Legajo

        _oIdioma = New cIdioma
        _oEstado_Usuario = New cEstado_Usuario

        _ListPassword = New List(Of cPassword)
        _ListPatenteFamilia = New List(Of cPatenteFamiliaElement)
    End Sub

    Public Function TieneAcceso(list As List(Of cPatenteFamiliaElement), strAccceso As String) As Boolean
        Dim obj As cPatenteFamiliaElement

        TieneAcceso = False

        For Each obj In list

            If TypeOf (obj) Is cPatente Then
                If obj.Nombre = strAccceso Then
                    TieneAcceso = True
                    Exit For
                End If
            End If

            If obj.ChildrenCount > 0 Then
                If TieneAcceso(obj.ListChilds, strAccceso) Then
                    TieneAcceso = True
                    Exit For
                End If
            End If
        Next

    End Function

End Class
